<template>
	<view class="box">
		<u-subsection :list="list" :current="type" activeColor="#333333" @change="setType"></u-subsection>
		<u-tabs :list="type==1?list2:list1" :current="current" lineColor="#FFCB71" @click="click" :scrollable="false">
		</u-tabs>


		<view class="comment-item" v-for="(item ,index) in dataList" :key="item.id"
			@click="goForumDetails(item.trends_id)">
			<view class="post-item-top-user" v-if="type">
				<view>
					<u-avatar class="avatar" :customStyle="{marginRight:'20rpx'}"
						:src="'https://wjlm.goldsu.cn'+item.user.pic" level-bg-color="#8072f3"></u-avatar>
				</view>
				<view class="center">
					<view style="display: flex;align-items: center;">
						<text class="username">{{ item.user.user.substring(0, 12) }}</text>
					</view>
					<view>
						<text class="time">{{$u.timeFrom(item.create_time, 'yyyy年mm月dd日 hh时MM分')}}</text>
					</view>
				</view>
			</view>

			<view class="comment">
				<text v-if="!type" class="time"
					style="margin-right: 10rpx;">{{$u.timeFrom(item.create_time, 'yyyy年mm月dd日 hh时MM分')}}</text>
				{{textTitle}}{{item.title.status==2?'的评论':'的动态'}}{{item.comment?`: ${item.comment}`:''}}
			</view>
			<view class="comment-title">
				<view class="" style="margin-right: 10rpx;">
					<text class="tag">动态</text>:
				</view>
				
				<u--text :lines="1" v-if="item.title.content" :text="item.title.content"></u--text>
				<image v-else-if="item.title.images" :src="item.title.images" mode=""></image>
					<u--text :lines="1" v-else :text="'原内容已被删除！'"></u--text>
			</view>
		</view>
		<u-empty v-if="dataList.length==0" marginTop="160rpx" text='暂无内容' mode="car"
			icon="http://cdn.uviewui.com/uview/empty/data.png">
		</u-empty>
		
		<Loading />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: ['我 点赞/评论 的动态', '点赞/评论 我的'],
				list2: [{
					name: '评论我'
				}, {
					name: '赞了我'
				}],
				list1: [{
					name: '我点赞'
				}, {
					name: '我评论'
				}],
				current: 0,
				type: 0, //0 和我互动，1我去互动
				dataList: []
			}
		},
		computed: {
			textTitle() {
				let name = `list${this.type+1}`
				return this[name][this.current].name
			}
		},
		onShow() {
			this.upData()
		},
		methods: {
			goForumDetails(id) {
				if (!id) return;
				uni.navigateTo({
					url: '../forumDetails?id=' + id
				});
			},
			upData() {
				this.dataList = []
				let url = 'home/user/user_trends_list'
				if (this.type == 1) {
					url = 'home/user/comment_like_list'
				}
				this.$myRuquest(url, {
					type: this.current + 1
				}).then(res => {
					this.dataList = res.data
				})
			},
			click(e) {
				this.current = e.index;
				this.upData()
			},

			setType(index) {
				this.type = index
				this.upData()
			}
		}
	}
</script>

<style lang="scss">
	.comment-item {
		padding: 20rpx 0;
		margin-bottom: 20rpx;
		border-bottom: 2rpx solid #f5f5f5;

		.post-item-top-user {
			display: flex;
			align-items: center;

			.avatar {
				width: 85rpx;
				height: 85rpx;
				border-radius: 50%;
				margin-right: 20rpx;
			}

			.center {
				flex: 1;
				display: flex;
				flex-direction: column;
				font-size: 24rpx;
				color: #999;

				.username {
					font-size: 32rpx;
					font-weight: 600;
					color: #616161;
				}

				.official {
					display: inline-block;
					font-size: 20rpx;
					color: #fff;
					background-color: $theme-color;
					padding: 5rpx 10rpx;
					border-radius: 10rpx;
					margin-right: 10rpx;
				}
			}
		}

		.comment {
			margin: 20rpx 0;
			font-size: 28rpx;
		}

		.comment-title {
			background-color: #f5f5f5;
			padding: 15rpx;
			color: #333;
			font-size: 28rpx;
			display: flex;
			align-items: center;
			image{
				width: 60rpx;
				height: 60rpx;
			}
		}
	}

	.box {
		padding: 20rpx;

	}

	.btn {
		width: calc(100vw - 40rpx);
		height: 60rpx;
		line-height: 60rpx;
		background-color: $theme-color;
		color: #fff;
		border-radius: 30rpx;
		text-align: center;
		box-shadow: 4rpx 4rpx 12rpx #ccc;
		margin-bottom: 40rpx;
	}
	.tag{
		padding: 4rpx 10rpx;
		background:rgba(255, 203, 113, .4);
		border-radius: 4rpx;
	}
</style>
